// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import VueRouter from 'vue-router';
import router from './router'
import axios from 'axios'
import VueAxios from 'vue-axios'
import ViewUI from 'view-design';
import 'view-design/dist/styles/iview.css';
import VueCharts from 'vue-chartjs'
import {Bar, Line} from 'vue-chartjs';
import store from './store'
import md5 from 'js-md5';
import qs from 'qs'
import { codemirror } from 'vue-codemirror'
import 'codemirror/lib/codemirror.css'
Vue.use(codemirror)
import VueClipboard from 'vue-clipboard2'
Vue.use(VueClipboard)


Vue.use(VueRouter)
Vue.use(ViewUI)
Vue.prototype.$qs = qs
Vue.prototype.$md5 = md5

// Vue.use(VueAxios, axios)
Vue.prototype.$axios = axios;

Vue.config.productionTip = false

Vue.use( VueCharts, {Bar,Line})


new Vue({
  el: '#app',
  store,
  router,
  components: { App },
  template: '<App/>'
})

/*axios.interceptors.request.use(
  config => {
    if(localStorage.getItem('Authorization')){
      config.headers.Authorization = localStorage.getItem('Authorization');
    }
    return config;
  },
  error => {
    return Promise.reject(error);
  }
)*/

axios.interceptors.request.use((config) => {
 if (config.method === 'post') {
    // config.data = qs.stringify(config.data);
    config.data = JSON.stringify(config.data);
  }
  return config;
},(error) =>{
  return Promise.reject(error);
});

//返回状态判断
axios.interceptors.response.use((res) =>{
  if(!res.data){  //这里根据接口返回的实际情况来写
    //这里是接口异常，可以统一弹窗提示错误信息
    return Promise.reject(res);
  }
  return res;
}, (error) => {
  //404等问题可以在这里处理
  return Promise.reject(error);
});
